	var drgQuotasData = {};//指标数据
	var drgDepQuotasData = {};//指标数据
	// 病组表格公共列
	var drgTableColumnsCommon = [
	                                {"data": "code","className":"fblack selooo"},
	                            	{"data": "InCaseCnt", "render":function(obj, type, full) {
	        	                  			if(full.InCaseCnt == 0){
		        		                    	return full.InCaseCnt ;
				                			} else {
		        		                    	return "<a href=\"javascript:void(0);\" onclick= \"loadCaseDtl('入组病例数','"+full.code+"','drgs', 'InCaseCnt')\">"+full.InCaseCnt+"</a>";
				                			}
	        		                	}
	                                },
		    	                  	{"data": "AvgDays"},
		    	                  	{"data": "AvgFee"},
		    	                	{"data": "CMI"},
		    	                  	{"data": "ExcessCnt_TF", "render":function(obj, type, full) {
		    	                  			if(full.ExcessCnt_TF == 0){
		        		                    	return full.ExcessCnt_TF ;
				                			} else {
			    		                    	return "<a href=\"javascript:void(0);\" onclick= \"loadCaseDtl('费用及住院日超标病例数','"+full.code+"','drgs', 'ExcessCnt_TF')\">"+full.ExcessCnt_TF+"</a>";
				                			}
		    		                	}
		    	                  	},
		    	                  	{"data": "SpecificCnt_TF", "render":function(obj, type, full) {
			    	                  		if(full.SpecificCnt_TF == 0){
		        		                    	return full.SpecificCnt_TF ;
				                			} else {
			    		                    	return "<a href=\"javascript:void(0);\" onclick= \"loadCaseDtl('费用及住院日特异病例数','"+full.code+"','drgs', 'SpecificCnt_TF')\">"+full.SpecificCnt_TF+"</a>";
				                			}
		    		                	}
		    	                  	}
		    	                 ];
	// 科室表格公共列
	var depTableColumnsCommon = [
                                    {"data": "code"},
	        	                  	{"data": "desc"},
	        	                  	{"data": "InCaseCnt", "render":function(obj, type, full) {
	        	                  			if(full.InCaseCnt == 0){
		        		                    	return full.InCaseCnt ;
				                			} else {
		        		                    	return "<a href=\"javascript:void(0);\" onclick= \"loadCaseDtl('入组病例数','"+full.code+"','dep', 'InCaseCnt')\">"+full.InCaseCnt+"</a>";
				                			}
	        		                	}
	                                },
	        	                  	{"data": "AvgDays"},
	        	                  	{"data": "AvgFee"},
	        	                  	{"data": "ExcessCnt_TF",
		    	                  		"render":function(obj, type, full) {
		    	                  			if(full.ExcessCnt_TF == 0){
		        		                    	return full.ExcessCnt_TF ;
				                			} else {
			    		                    	return "<a href=\"javascript:void(0);\" onclick= \"loadCaseDtl('费用及住院日超标病例数','"+full.code+"','dep', 'ExcessCnt_TF')\">"+full.ExcessCnt_TF+"</a>";
				                			}
		    		                      }
		    	                  	},
		    	                  	{"data": "SpecificCnt_TF",
		    	                  		"render":function(obj, type, full) {
		    	                  			if(full.SpecificCnt_TF == 0){
		        		                    	return full.SpecificCnt_TF ;
				                			} else {
			    		                    	 return "<a href=\"javascript:void(0);\" onclick= \"loadCaseDtl('费用及住院日特异病例数','"+full.code+"','dep', 'SpecificCnt_TF')\">"+full.SpecificCnt_TF+"</a>";

				                			}
		    		                	}
		    	                  	},
	        	                  	{"data": "operation",
	        	                  		"render":function(obj, type, full) {
	        		                    	  return "<a href=\"javascript:void(0);\" keyDisGroupCode = '"+full.code+"'><i class = 'fa fa-line-chart'></i></a>";
	        		                      }
	                          		},
	        	                 ] ;
	
	
	// 病组表格指标请求计数
	var ajaxcount_keyDisDrgs = 0 ;
	// 科室表格指标请求计数
	var ajaxcount_keyDisDep = 0 ;
	 /*
	  *  i 请求的指标数组的下标
	  *  quotas 指标数组
	  *  type 监测类型
	  *  table的ID
	  *  表格的列
	  */
	function getTableData(i,type,quotas,tableId,drgDayFeeTableColumns,specHeader){
		var monitorType = type;
		if(i == 0 && type == "drgs") {
			ajaxcount_keyDisDrgs += quotas.length ;
		} else if(i == 0 && (type == "dep"||type == "clinic")) {
			ajaxcount_keyDisDep += quotas.length ;
		}
		//公共的参数
		var param=drgUI.setAjaxData(tabId);
		param.isGetCc = '0' ;
		param.specHeader = specHeader ;
		param.monitorType = type ;
		param.quotaCode =quotas[i] ;
		$.post(contextPath + "/DrgsIndexCal/indexCal.dhc",param).done(function(result){
			if(type == "drgs") {
				drgQuotasData[quotas[i]] = result.data ;
				ajaxcount_keyDisDrgs -- ;
			} else {
				drgDepQuotasData[quotas[i]] = result.data ;
				ajaxcount_keyDisDep -- ;
			}
			if( ajaxcount_keyDisDrgs == 0 && type == "drgs" ) {
				drawKeyDisGroupTable(assembleQuotaData(quotas,drgQuotasData) ,drgDayFeeTableColumns ,tableId);
				//增加对传入的quotas的判断
		    	if(quotas[1]=="AvgDays") {
		    		keyDisGroupTrendChart('AvgDaysθAvgFee',type);
		    	} else {
		    		keyDisGroupTrendChart('AvgFeeθDrugRatio',type);
		    	}
			} 
			if( ajaxcount_keyDisDep == 0 && (type == "dep"||type == "clinic") ) {
				drawKeyDisGroupTable(assembleQuotaData(quotas,drgDepQuotasData) ,drgDayFeeTableColumns ,tableId,true);
			    $('#'+tabId + ' #'+tableId+' tbody tr').on( 'click', 'i', function () {
			    	$(this).toggleClass("selooo");
			    	if(!$('#'+tabId+' .depQuota').parent().hasClass("active"))
		    		{//当科室页签没有显示时  显示科室页签
			    		$('#'+tabId+' .depQuota').click();
		    		}
			    	//增加对传入的quotas的判断
			    	if(quotas[1]=="AvgDays") {
			    		keyDisGroupTrendChart('AvgDaysθAvgFee',type);
			    	} else {
			    		keyDisGroupTrendChart('AvgFeeθDrugRatio',type);
			    	}
		        });
			}
		});
		
		if(i+1<quotas.length) {
			getTableData(i+1,type,quotas,tableId,drgDayFeeTableColumns) ;
		}  
}

	/**
	 * 将返回的指标数据组装成表格所需格式的数据
	 * @param quotas
	 * @param quotasData
	 * @returns {Array}
	 */
	function assembleQuotaData(quotas,quotasData)
	{
		var assembledQuotasData = [];
		
		for(var i = 0;i<quotas.length;i++)
		{
			var quotaData = quotasData[quotas[i]];
			if(quotaData == undefined || quotaData ==null ) break ;
			for(var j = 0;j<quotaData.length;j++)
			{
				if(i != 0)
				{
					assembledQuotasData[j][quotas[i]] =quotaData[j].QuotaValue;
				}
				else 
				{
					var rowData = {};
					rowData.code = quotaData[j].ccode;
					rowData.desc = quotaData[j].ddesc;
					rowData[quotas[i]] = quotaData[j].QuotaValue;
					assembledQuotasData.push(rowData);
				}
			}
		}
		return assembledQuotasData ;
	}
	
	
	
	// 绘制表格
	function drawKeyDisGroupTable(data, columns, divId,visibleFlag){
		var paramsDataTables={searching:false,paging:false,lengthChange:false,info:false,ordering:false,tableTitle:'重点病组指标情况表'};
		if(visibleFlag){//病组详情页面 科室表格需要隐藏第一列
			paramsDataTables.paging=true;
			paramsDataTables.columnDefs=[{"orderable": false,"targets": [ 0 ] },{ "visible": false, "targets": [0]}]
		}
		return $("#"+tabId+" #"+divId).dataTableBasic(columns,data,paramsDataTables);
	}
	 
//获取病例费用分布数据
function getCaseFeeDistribute()
{	
	$('#'+tabId+' .drgFeeDistribute table').empty();
	var sliderValue = $('#'+tabId+' .drgFeeDistribute .filterSlider').val()*1;//滑块值
	var param=drgUI.setAjaxData(tabId);
	param.sliderValue = sliderValue ;
	$.post(contextPath + "/keyDisGroup/getCaseFeeDistribute.dhc",param).done(function(result){
		var data = result.data;
		var stdfee;//在调用getTitleDesc方法前先确保stdfee有值，	然后都取此值，就不用每次循环都从data中取
		for (var i = 0; i < data.length; i++) {
			if (data[i].STDFEE>0) {
				stdfee = data[i].STDFEE;// 费用标杆
				break;
			}
		}
		var calzz = $('#'+tabId+' .drgFeeDistribute').attr("class");
		var feeDistrbute = [];//费用分布
		//费用分布配置
		var compareType = $("#searchcq").children().eq(3).find("a.active").attr("data-value");//加入比较类型，来控制区间病例显示类型
		var feeDistrbuteConfig = {"legendShow":false,radius:[0,'60%']};
		for(var i=0;i<data.length;i++)
		{
			var feeinterval = data[i].FEEINTERVAL;//区间类别
			var title = getTitleDesc(sliderValue,feeinterval,true,"",compareType);
			feeDistrbute.push({name:title,value:data[i].INCNT});
		}
		pieCharts($('#'+tabId+' .drgFeeDistribute .chart'), feeDistrbute, '病例费用分布', '',feeDistrbuteConfig);
		if(calzz.indexOf('distributedrug')>0)
		{
			$('#'+tabId+' .drgFeeDistribute table').append('<thead><tr><th>区间内病例类型</th><th>费用区间范围</th><th>入组病例数</th><th>次均费用(元)</th><th>药占比(%)</th><th>权重</th></tr></thead><tbody></tbody>');
			
			for(var i=0;i<data.length;i++)
			{
				var feeinterval = data[i].FEEINTERVAL;//区间类别
				var title = getTitleDesc(sliderValue,feeinterval,false,stdfee,compareType);
				if(data[i].INCNT>0)
				{
					$('#'+tabId+' .drgFeeDistribute table tbody').append("<tr>"+title+"<td><a href=\"javascript:void(0);\" onclick= \"loadCaseDtl('入组病例数','"+paramTabPage[tabId].drgCode+"','drgs', 'ExcessCnt_F',"+sliderValue+","+feeinterval+")\">"+data[i].INCNT+"</a></td><td>"+data[i].AVGFEE+"</td><td>"+data[i].DRUGRATIO+"</td><td>"+data[i].TOTALWEIGHT+"</td></tr>");
				}
				else
				{
					$('#'+tabId+' .drgFeeDistribute table tbody').append("<tr>"+title+"<td>"+data[i].INCNT+"</td><td>-</td><td>-</td><td>-</td></tr>");
				}
			}
		}
		else
		{
			$('#'+tabId+' .drgFeeDistribute table').append('<thead><tr><th>区间内病例类型</th><th>费用区间范围</th><th>入组病例数</th><th>平均住院日</th><th>次均费用(元)</th><th>总权重</th></tr></thead><tbody></tbody>');
			
			for(var i=0;i<data.length;i++)
			{
				var feeinterval = data[i].FEEINTERVAL;//区间类别
				var title = getTitleDesc(sliderValue,feeinterval,false,stdfee,compareType);
				if(data[i].INCNT>0)
				{
					$('#'+tabId+' .drgFeeDistribute table tbody').append("<tr>"+title+"<td><a href=\"javascript:void(0);\" onclick= \"loadCaseDtl('入组病例数','"+paramTabPage[tabId].drgCode+"','drgs', 'ExcessCnt_F',"+sliderValue+","+feeinterval+")\">"+data[i].INCNT+"</a></td><td>"+data[i].AVGDAY+"</td><td>"+data[i].AVGFEE+"</td><td>"+data[i].TOTALWEIGHT+"</td></tr>")
				}
				else
				{
					$('#'+tabId+' .drgFeeDistribute table tbody').append("<tr>"+title+"<td>"+data[i].INCNT+"</td><td>-</td><td>-</td><td>-</td></tr>");
				}
			}
		}
	});
}
/**
 * 获取相应描述值
 * @param sliderValue 滑块值
 * @param feeinterval 区间范围代码
 * @param isChart 是否是饼图标识 
 * @param stdfee 费用标杆
 * @returns {String}
 */
function getTitleDesc(sliderValue,feeinterval,isChart,stdfee,compareType)
{
	var compareTypeDesc="";
	if(compareType=="manage"){
		compareTypeDesc="绩效值";
	} 
	else if(compareType=="std")
	{
		compareTypeDesc="标杆值";
	}
	else{
		compareTypeDesc="院内均值";
	}
	var title = "";
	switch(feeinterval)
	{
	case 1:
		if(isChart)
		{
			compareType=="manage"?title = "超标"+sliderValue+"%\n及以上病例":title = "超出"+compareTypeDesc+sliderValue+"%\n及以上病例";
		}
		else
		{
			compareType=="manage"?title = "<th>超标"+sliderValue+"%及以上病例</th><td>["+formatNumKeyDisGroup(stdfee*(100+sliderValue)/100,"-") +",∞)</td>":title = "<th>超出"+compareTypeDesc+sliderValue+"%及以上病例</th><td>["+formatNumKeyDisGroup(stdfee*(100+sliderValue)/100,"-")+",∞)</td>";
		}
		break;
	case 2:
		if(isChart)
		{
			compareType=="manage"?title = "超标"+sliderValue+"%\n以内病例":title = "超出"+compareTypeDesc+sliderValue+"%\n以内病例";
		}
		else
		{
			compareType=="manage"?title = "<th>超标"+sliderValue+"%以内病例</th><td>("+formatNumKeyDisGroup(stdfee, 2) +","+formatNumKeyDisGroup(stdfee*(100+sliderValue)/100,"-") +")</td>":title = "<th>超出"+compareTypeDesc+sliderValue+"%以内病例</th><td>("+formatNumKeyDisGroup(stdfee,"-")+","+formatNumKeyDisGroup(stdfee*(100+sliderValue)/100,"-") +")</td>";
		}
		break;
	case 3:
		if(isChart)
		{
			compareType=="manage"?title = "低于标杆"+sliderValue+"%\n以内病例":title = "低于"+compareTypeDesc+sliderValue+"%\n以内病例";
		}
		else
		{
			compareType=="manage"?title = "<th>低于标杆"+sliderValue+"%以内病例</th><td>("+formatNumKeyDisGroup(stdfee*(100-sliderValue)/100,"-")+","+formatNumKeyDisGroup(stdfee,"-")+"]</td>":title = "<th>低于"+compareTypeDesc+sliderValue+"%以内病例</th><td>("+formatNumKeyDisGroup(stdfee*(100-sliderValue)/100,"-") +","+formatNumKeyDisGroup(stdfee,"-") +"]</td>";
		}
		break;
	case 4:
		if(isChart)
		{
			compareType=="manage"?title = "低于标杆"+sliderValue+"%\n及以上病例":title = "低于"+compareTypeDesc+sliderValue+"%\n及以上病例";
		}
		else
		{
			compareType=="manage"?title = "<th>低于标杆"+sliderValue+"%及以上病例</th><td>(0,"+formatNumKeyDisGroup(stdfee*(100-sliderValue)/100,"-")+"]</td>":title = "<th>低于"+compareTypeDesc+sliderValue+"%及以上病例</th><td>(0,"+formatNumKeyDisGroup(stdfee*(100-sliderValue)/100,"-") +"]</td>";
		}
		break;
	default:
		if(isChart)
		{
			title = "未定义";
		}
		else
		{
			title = "<th>未定义</th><td>--</td>";
		}
		break;
	}
	return title;
}
function keyDisGroupTrendChart(quotas,type)
{
	
	var monitorType = 'drgs';//默认检测类型是drg
	if($('#'+tabId+' .drgDepTable  tbody tr .selooo').size()>0 && $('#'+tabId+' .drgTable tbody tr').size()>0)
	{
		monitorType = type;//当drg没被选中时只加载drg下的科室或主诊组
	}
	var deps = '';//科室代码
	var clinics	= '';//主诊组代码
	$('#'+tabId+' .drgDepTable tbody tr .selooo').each(function(){
		if(monitorType=="dep"){
			deps += $(this).parent().attr("keydisgroupcode")+"θ";//被选中的科室代码
		}else{
			clinics += $(this).parent().attr("keydisgroupcode")+"θ";//被选中的主诊组代码
		}
	});
	if(monitorType=="dep"){
		deps = deps.substring(0,deps.length-1); //去掉最后一个字符
	}else{
		clinics = clinics.substring(0,clinics.length-1); //去掉最后一个字符
	}
	$.post(contextPath + "/keyDisGroup/getQuadrantTrendData.dhc", {
		'dateFrom' : paramTabPage[tabId].dateFrom,//开始时间
		'dateTo' : paramTabPage[tabId].dateTo,//结束时间
		'mrType' : paramTabPage[tabId].mrType,
		'pType' : paramTabPage[tabId].pType,//病人类型  0：前提病人 1.医保病人 默认为0
		'monitorType' : monitorType,//比较对象： Hosp dep depGroup  mdc adrg drgs ward（病区） resident（住院医师） protomedicus（主任医师）physician（主治医师）
		'pardepCode' : paramTabPage[tabId].depCode,//科室代码、
		'deps' : deps ,//科室
		'pardepgroupCode' : paramTabPage[tabId].depGroupCode,//科室组代码
		'pargroupName' : clinics,//paramTabPage[tabId].groupName,//主诊组
		'parwardCode': paramTabPage[tabId].wardCode,//病区代码
		'protomedicus':paramTabPage[tabId].protomedicus,//主任医师
		'physician' :paramTabPage[tabId].physician,//主治医师
		'resident' :paramTabPage[tabId].resident,//住院医师
		'parmdcCode' : paramTabPage[tabId].mdcCode,//mdc代码
		'paradrgCode' : paramTabPage[tabId].adrgCode,//adrg代码
		'pardrgCode' : paramTabPage[tabId].drgCode,//drg代码
		'quotaCode':quotas
	}).done(function(result){
		var quotaCodes = quotas.split("θ");
		for(var i = 0;i<quotaCodes.length;i++)
		{
			var quotaTrendData = result.data[quotaCodes[i]];
			var lines = [];
			var datas = [];
			if(quotaTrendData){
				for(var key in quotaTrendData){
					var line = {"code": "QuotaValue", "desc": key, "data":[]};
					lines.push(line);
					datas.push(quotaTrendData[key]);
				}
			}
			var chartParams={legendPosition:'bottom'}
			if(paramTabPage[tabId].mrType=='custom'){
				chartParams.gridLeft=30;
				chartParams.gridRight=55;
			}
			lineChartBasic($('#'+tabId+' .trendchart>div:eq('+i+')>div>div'), lines, datas, '','',chartParams);
		}
	});
}

function initSlider()
{
	$("#"+tabId+" .filterSlider").slider({
		min: 1, max: 99 , range: false, value: 20,
	    reversed : false,
	});
	$("#"+tabId+" .slider").css("display","block");
	$("#"+tabId+" .filterSlider").on("slideStop",function(slideEvt) {
		getCaseFeeDistribute();
	});
}

 
function loadCaseDtl(title, ccode, monitorType, quotaCode, sliderValue,costInterval){
	var param=drgUI.setAjaxData(tabId);
	param.isGetCc = "0" ;
	param.monitorType = monitorType ;
	param.quotaCode = quotaCode ;
	param.typeOne = sliderValue ;
	param.typeTwo = costInterval ;
	param.caseLinkCode = quotaCode;
	param.title = title;
	if(ccode){
		if(monitorType == "depGroup"){
			param.depGroupCode=ccode;
		}else if(monitorType == "dep"){
			param.depCode=ccode;
		}else if(monitorType == "ward"){
			param.wardCode=ccode;
		}else if(monitorType == "clinic"){
			param.groupName=ccode;
		}else if(monitorType == "mdc"){
			param.mdcCode=ccode;
		}else if(monitorType == "adrg"){
			param.adrgCode=ccode;
		}else if(monitorType == "drgs"){
			param.drgCode=ccode;
		}
	}
	openTab('/pages/drgscommon/case.jsp', title+"明细", "caseDtl"+monitorType+ccode+quotaCode, "caseDtl"+monitorType+ccode+quotaCode, param);
}

// 保存散点线图
function saveChartStatus(thisObj ,chartStatus) {
	var echartDivId = thisObj.parents("ul").find("li.quotasTab.active > a").attr("href") ;
	if(thisObj.hasClass("btn-success")){
		thisObj.removeClass("btn-success");
		thisObj.addClass("btn-warning");
		if(jQuery.inArray(echartDivId, chartStatus) == -1){
			chartStatus.push(echartDivId) ;
		}
	} else {
		array_remove(chartStatus, echartDivId) ;
		thisObj.removeClass("btn-warning");
		thisObj.addClass("btn-success");
	}
}

/**
 * 格式化方法
 * @@param num
 * @@param decimal
 * @@returns
 * @any
 * @ Discription:
 * @keyDiseaseGroupCommon.js
 */
function formatNumKeyDisGroup(num,decimal) {
	if(!num || isNaN(num)) {
		if(isNaN(decimal)) {
			return decimal ;
		} else {
			return formatNumber("0",decimal) ;
		}
	} 
	return formatNumber(num,decimal)
}